package com.comba.nutz.boot.auth.server.entity;

import lombok.Getter;
import lombok.Setter;
import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Table;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.oauth2.provider.ClientDetails;

import java.util.*;

/**
 * 客户端信息表
 *
 * @author george
 */
@Table("system_client")
@Getter
@Setter
public class ClientEntity implements ClientDetails {

    /**
     * 客户端ID。
     */
    @Column("client_id")
    private String clientId;

    /**
     * 客户端密码
     */
    @Column("client_secret")
    private String clientSecret;

    /**
     * 访问令牌有效性秒
     */
    private Integer accessTokenValiditySeconds;

    /**
     * 刷新令牌有效性秒
     */
    private Integer refreshTokenValiditySeconds;

    @Override
    public Set<String> getResourceIds() {
        return null;
    }

    @Override
    public boolean isSecretRequired() {
        return false;
    }

    @Override
    public boolean isScoped() {
        return true;
    }

    @Override
    public Set<String> getScope() {
        Set<String> scope = new HashSet<>();
        scope.add("scope");

        return scope;
    }

    @Override
    public Set<String> getAuthorizedGrantTypes() {
        Set<String> authorizedGrantTypes = new HashSet<>();
        authorizedGrantTypes.add("password");
        authorizedGrantTypes.add("authorization_code");
        authorizedGrantTypes.add("refresh_token");
        authorizedGrantTypes.add("client_credentials");

        return authorizedGrantTypes;
    }

    @Override
    public Set<String> getRegisteredRedirectUri() {
        return null;
    }

    @Override
    public Collection<GrantedAuthority> getAuthorities() {
        List<GrantedAuthority> authorityList = new ArrayList<GrantedAuthority>();

        GrantedAuthority grantedAuthority = new GrantedAuthority() {
            @Override
            public String getAuthority() {
                return "USER_ROLE";
            }
        };

        authorityList.add(grantedAuthority);

        return authorityList;
    }

    @Override
    public boolean isAutoApprove(String scope) {
        return false;
    }

    @Override
    public Map<String, Object> getAdditionalInformation() {
        return null;
    }
}
